package com.linwen.excise.leetcode;

/**
 * @ClassName _278第一个错误版本
 * @Description 第一个错误版本
 * @Author lin
 * @Date 2021/11/7 下午12:47
 * @Version V1.0
 */
public class _278第一个错误版本 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int i = solution.firstBadVersion(5);
        System.out.println(i);

    }
static class VersionControl{
    public boolean isBadVersion(int n) {
        return n==4;
    }
}
static class Solution extends VersionControl {
    public int firstBadVersion(int n) {
        int start = 0;
        int end = n;
        while(start<end){
            int mid = start + (end-start)/2;
            if(isBadVersion(mid)){
                end = mid;
            }else{
                start = mid+1;
            }
        }
        return start;
    }
    }
}
